<?php

namespace app\api\controller;



use app\api\model\house\House as HouseModel;
use app\api\model\house\HouseEvaluateComment as HouseEvaluateCommentModel;
use app\common\controller\Api;
use app\api\model\house\HouseEvaluate as HouseEvaluateModel;

class Houseevaluatecomment extends Api
{
    protected $noNeedRight = ['*'];


    //评论评价
    public function comment()
    {
        $comment_model = new HouseEvaluateCommentModel();

        $data = [
            'user_id'=>$this->auth->id,
            'evaluate_id'=>input('evaluate_id',0),
            'content'=>input('content',''),
        ];

        $info = HouseEvaluateModel::get($data['evaluate_id']);

        if (empty($info))$this->error('评价不存在');

        if (empty($data['evaluate_id']))$this->error('缺少参数评价id');

        if (empty($data['content']))$this->error('请输入评论内容');

        $res = $comment_model->save($data);

        $this->success('评论成功');
    }

    //评论列表
    public function commentlists()
    {
        $page_size = input('page_size',10);
        $evaluate_id = input('evaluate_id',0);

        $where = ['ge.user_id'=>$this->auth->id,'ge.evaluate_id'=>$evaluate_id];

        $list = HouseEvaluateCommentModel::alias('ge')
            ->join('user u','ge.user_id = u.id')
            ->where($where)
            ->field('ge.*,u.nickname,u.avatar')
            ->order('ge.createtime desc')
            ->paginate($page_size, false, ['query' => request()->get()]);

        $this->success('',$list);

    }
}